package com.moyun.finance.controller;

import com.moyun.finance.entity.Account;
import com.moyun.finance.entity.Customer;
import com.moyun.finance.entity.Response;
import com.moyun.finance.entity.Transfer;
import com.moyun.finance.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    AccountService as;

    //账户新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody Account account){
        Response res = as.save(account);
        return res;
    }

    //账户修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody Account account){
        Response res = as.update(account);
        return res;
    }

    //账户删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody Account account){
        Response res = as.delete(account);
        return res;
    }

    //查询指定公司所有账户
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByDeptId(String companyId){
        List<Account> accounts = as.findAll(companyId);
        return new Response("",accounts,true);
    }

    //根据id查账户
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String accountId){
        Account acs = as.findOneById(accountId);
        return new Response("",acs,true);
    }

    //公司下所有账户余额，流出，流入总计
    @RequestMapping("/count")
    public @ResponseBody Response count(String companyId){
        Map<String,Double> countMap = as.count(companyId);
        return new Response("",countMap,true);
    }

    //账户间转账
    @RequestMapping("/transfer")
    public @ResponseBody Response transfer(@RequestBody Transfer transfer){
        Response res = as.transfer(transfer);
        return new Response("",res,true);
    }
}
